import { createStore } from 'vuex'
import axios from "axios";

export default createStore({
  strict: true,
  state: {
    departments: [],
    registLevel: [],
    currentPatient: {},
    diseaseSearchVisible: false,
    techSearchVisible: false
  },
  getters: {
  },
  mutations: {
    setDepartments(state, value) {
      state.departments = value
    },
    setRegistLevel(state, value) {
      state.registLevel = value
    },
    setCurrentPatient(state, value) {
      state.currentPatient = value
    },
    setDiseaseSearchVisible(state, value) {
      state.diseaseSearchVisible = value
    },
    setTechSearchVisible(state, value) {
      state.techSearchVisible = value
    }
  },
  actions: {
    requestDepartments(context) {
      if (context.state.departments.length == 0) {
        axios({
          url: "/api/department/query",
        }).then(res => {
          context.commit("setDepartments", res.data.data);
        }).catch(err => {
        }).then(() => {
        })
      }
    },
    requestRegistLevel(context) {
      if (context.state.registLevel.length == 0) {
        axios({
          url: "/api/register_level/query"
        }).then(res => {
          context.commit("setRegistLevel", res.data.data)
        }).catch(err => {
        }).then(() => {
        })
      }
    }
  },
  modules: {
  }
})
